import type { ClientCacheServiceResult } from "./ClientCache";

export const ClientIndexService = (cache: ClientCacheServiceResult) => {
  return {
    /**
     * 创建一个索引结构
     */
    async listIndex(id: string) {
      const client = await cache.getClientCache(id);
      return client.indices();
    },
    /**
     * 创建一个索引结构
     */
    async getIndex(id: string, index: string) {
      const client = await cache.getClientCache(id);
      return client.getIndex(index);
    },
    /**
     * 创建一个索引结构
     */
    async createIndex(id: string, data: string) {
      const client = await cache.getClientCache(id);
      await client.createIndex(data);
    },

    /**
     * 更新一个索引结构
     */
    async updateIndex(id: string, index: string, data: string) {
      const client = await cache.getClientCache(id);
      await client.updateIndex(index, data);
    },

    /**
     * 删除多个索引
     */
    async deleteBatchIndex(id: string, indexIds: Array<string>) {
      const client = await cache.getClientCache(id);
      await client.deleteBatchIndex(indexIds);
    },

    /**
     * 删除多个索引
     */
    async addAlias(id: string, index: string, alias: string) {
      const client = await cache.getClientCache(id);
      return client.addAlias(index, alias);
    },

    /**
     * 删除多个索引
     */
    async removeAlias(id: string, index: string, alias: string) {
      const client = await cache.getClientCache(id);
      return client.removeAlias(index, alias);
    }
  };
};
